package com.hunktimes.wholesale.base

import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.annotation.StringRes
import com.gyf.immersionbar.ImmersionBar
import com.gyf.immersionbar.ktx.isSupportStatusBarDarkFont
import com.hunktimes.wholesale.R

/**
 * Author: Delete
 * Date: 2020/7/31 13:54
 * Description:
 *
 */
open class BaseTitleFragment : BaseFragment {

    constructor() : super()
    constructor(contentLayoutId: Int) : super(contentLayoutId)

    @StringRes
    protected open val titleRes: Int = R.string.app_name

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val titleTv: TextView? = view.findViewById(R.id.title_tv)
        titleTv?.text = getString(titleRes)

        if (enableImmersionBar()) {
            initImmersionBar()
        }
    }

    protected open fun enableImmersionBar() = true

    protected open fun initImmersionBar() {
        ImmersionBar.with(this)
            .apply {
                if (isSupportStatusBarDarkFont) {
                    statusBarDarkFont(true)
                }
                val titleBar: View? = view?.findViewById(R.id.title_bar)
                if (null != titleBar) {
                    titleBar(R.id.title_bar)
                }
            }.init()

    }

}